package com.ruoyi.manager.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manager.domain.ArvinServer;
import com.ruoyi.manager.service.IArvinServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务器管理Controller
 * 
 * @author ruoyi
 * @date 2021-08-22
 */
@RestController
@RequestMapping("/server/server")
public class ArvinServerController extends BaseController
{
    @Autowired
    private IArvinServerService arvinServerService;

    /**
     * 查询服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('server:server:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArvinServer arvinServer)
    {
        startPage();
        List<ArvinServer> list = arvinServerService.selectArvinServerList(arvinServer);
        return getDataTable(list);
    }

    /**
     * 导出服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('server:server:export')")
    @Log(title = "服务器管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArvinServer arvinServer)
    {
        List<ArvinServer> list = arvinServerService.selectArvinServerList(arvinServer);
        ExcelUtil<ArvinServer> util = new ExcelUtil<ArvinServer>(ArvinServer.class);
        return util.exportExcel(list, "server");
    }

    /**
     * 获取服务器管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:server:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(arvinServerService.selectArvinServerById(id));
    }

    /**
     * 新增服务器管理
     */
    @PreAuthorize("@ss.hasPermi('server:server:add')")
    @Log(title = "服务器管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArvinServer arvinServer)
    {
        arvinServer.setUserId(getUserId());
        return toAjax(arvinServerService.insertArvinServer(arvinServer));
    }

    /**
     * 修改服务器管理
     */
    @PreAuthorize("@ss.hasPermi('server:server:edit')")
    @Log(title = "服务器管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArvinServer arvinServer)
    {
        return toAjax(arvinServerService.updateArvinServer(arvinServer));
    }

    /**
     * 删除服务器管理
     */
    @PreAuthorize("@ss.hasPermi('server:server:remove')")
    @Log(title = "服务器管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arvinServerService.deleteArvinServerByIds(ids));
    }
}
